//TODO a(41)
function a41(module, exports, a) {
    function i() {
        this.remoteTimer = null, this.localTimer = null, this.remoteLastTime = 0, this.localLastTime = 0
    }

    var s = a(23), r = a(3), n = a(2), o = a(21), l = a(42);
    r.extend(i, s);
    var d = {
        init: function () {
            this.playerData = this.manager.playerData, this.vinfo = this.playerData.vinfo, this.reader = new c(this.vinfo), this.saver = new h(this.vinfo, this.reader), this.initRecord = !0, this.manager.listener.on(o.PLAY_STATE, function (e, t) {
                "play" == t || "seeking" == t ? (this.initRecord && (this.flush(0, !0), this.initRecord = !1), this.startRecord()) : this.stopRecord(), "ended" == t && this.flush(-1, !0), "init" != t && "stop" != t || (this.initRecord = !0, this.reader.stop())
            }, this), this.flag = !1, this.isLogin = !1, this.manager.listener.on(o.USER_INFO, function (e, t) {
                this.isLogin = null != t, this.isLogin ? this.startRemoteRecord() : this.stopRemoteRecord()
            }, this)
        }, initData: function (e) {
            "none" != this.playerData.tryLookType || this.playerData.vinfo.gdur < 600 ? (this.flag = !1, e && e()) : (this.flag = !0, this.isLogin && 0 == this.playerData.flashVar.isHttps ? this.reader.refreshRemote(e) : (this.reader.refreshLocal(), e()))
        }, flush: function (e, t) {
            (this.flag && !isNaN(e) || t) && (this.saver.flushLocal(e), this.isLogin && 0 == this.playerData.flashVar.isHttps && this.saver.flushRemote(e))
        }, getRecords: function () {
            var e = this.reader.records, t = this.vinfo.vid;
            if (e && e.length > 0 && t > 0)for (var a = 0; a < e.length; a++)if (e[a].vid === t)return e[a].htime;
            return -1
        }, startRecord: function () {
            this.startLocalRecord(), this.isLogin && this.startRemoteRecord()
        }, startLocalRecord: function () {
            this.flag && (this.stopLocalRecord(), this.localTimer = setInterval(r.bind(function () {
                this.saver.flushLocal(this.manager.curVideo.getCurrentTime())
            }, this), 3e3))
        }, startRemoteRecord: function () {
            this.flag && (this.stopRemoteRecord(), this.isLogin && 0 == this.playerData.flashVar.isHttps && (this.remoteTimer = setInterval(r.bind(function () {
                this.saver.flushRemote(this.manager.curVideo.getCurrentTime())
            }, this), 12e4)))
        }, stopRecord: function () {
            this.stopLocalRecord(), this.stopRemoteRecord()
        }, stopLocalRecord: function () {
            clearInterval(this.localTimer)
        }, stopRemoteRecord: function () {
            clearInterval(this.remoteTimer)
        }
    };
    r.merge(i.prototype, d);
    var h = function (e, t) {
        this.vinfo = e, this.reader = t, this._fromID = n.letvTv ? 4 : n.iPad ? 3 : n.Android || n.iPhone || n.iPod || n.wph || n.ps ? 2 : 1
    };
    h.prototype = {
        flushRemote: function (e) {
            if (e != this.remoteLastTime && this.vinfo) {
                this.remoteLastTime = e;
                var t = this.vinfo, a = o.PROTOCAL + o.HOST_NAME.API_MY_LETV_COM + "/vcs/set?htime=" + e + "&cid=" + t.cid + "&pid=" + t.pid + "&vid=" + t.vid + "&nvid=" + (t.nextvid || "") + "&from=" + this._fromID;
                r.sendRequest(a)
            }
        }, flushLocal: function (e) {
            if (e != this.localLastTime && this.vinfo) {
                this.localLastTime = e;
                for (var t = this.reader.records, a = t.length - 1; a >= 0; a--)t[a].vid == this.vinfo.vid && t.splice(a, 1);
                var i = {vid: this.vinfo.vid, htime: e, utime: r.now()};
                for (t.unshift(i); t.length > 10;)t.pop();
                this.reader.records = t;
                try {
                    l.set("letvPlayerHistory", this.reader.records)
                } catch (s) {
                }
            }
        }
    };
    var c = function (e) {
        this.vinfo = e, this.records = [], this.jsonp = null
    };
    c.prototype = {
        refreshRemote: function (e) {
            var t = this;
            this.jsonp = r.getJSON({
                url: o.PROTOCAL + o.HOST_NAME.API_MY_LETV_COM + "/vcs/get",
                data: {vid: this.vinfo.vid, tn: Math.random()},
                success: function (a) {
                    t.jsonp = null, 200 == a.code && (a.data.vid = t.vinfo.vid, t.records = [a.data]), e && e()
                },
                fail: function () {
                    t.jsonp = null, e && e()
                }
            })
        }, refreshLocal: function () {
            try {
                return this.records = l.get("letvPlayerHistory") || []
            } catch (e) {
                return []
            }
        }, stop: function () {
            this.jsonp && this.jsonp.destroy()
        }
    }, module.exports = i
}
